package com.atguigu.srb.core.controller.admin;


import com.atguigu.srb.base.util.JwtUtils;
import com.atguigu.srb.common.exception.Assert;
import com.atguigu.srb.common.result.R;
import com.atguigu.srb.common.result.ResponseEnum;
import com.atguigu.srb.core.pojo.entity.Borrower;
import com.atguigu.srb.core.pojo.vo.BorrowerApprovalVO;
import com.atguigu.srb.core.pojo.vo.BorrowerDetailVO;
import com.atguigu.srb.core.pojo.vo.BorrowerVO;
import com.atguigu.srb.core.service.BorrowerService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author LiLi
 * @since 2021-09-23
 */
@RestController
@RequestMapping("/admin/core/borrower")
@Api("后台管理借款额度审核")
@Slf4j
public class AdminBorrowerController {
    @Autowired
    BorrowerService borrowerService;
    @ApiOperation("借款额度审批")
    @PostMapping("/approval")
    public R approval(@RequestBody BorrowerApprovalVO borrowerApprovalVO) {
        borrowerService.approval(borrowerApprovalVO);
        return R.ok().message("审批完成");
    }

    @ApiOperation("借款人列表(额度申请)")
    @GetMapping("show/{id}")
    public R show(@PathVariable("id") Long id){
        BorrowerDetailVO borrowerDetailVO = borrowerService.show(id);
        return R.ok().data("borrowerDetailVO",borrowerDetailVO);
    }

    @ApiOperation("借款人列表(额度申请)")
    @GetMapping("list/{page}/{limit}")
    public R list(
            @ApiParam("当前页")
            @PathVariable("page")
            Long page,
            @ApiParam("每页多少条")
            @PathVariable("limit")
            Long limit,
            @ApiParam("关键字")
            String keyword
            ){
        Page<Borrower> pageParam = new Page(page,limit);
        Page<Borrower> pageModel = borrowerService.listPage(pageParam,keyword);
        return R.ok().data("pageModel",pageModel);
    }

}

